package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 保险订单
 */
@Setter
@Getter
public class InsuranceOrder extends BaseDomain {

    // 保险产品名称
    private String productName;

    // 保险产品
    private InsuranceProduct product;

    // 保险产品类型
    private Insurance insurance;

    // 客户名称
    private String clientName;

    // 订单金额
    private BigDecimal orderAmount;

    // 创建订单时间
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date orderTime;

    /*---------新增---------------------------------------------------------------------------*/
    // 保险生效初始日期
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date startDate;

    // 保险失效日期
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date endDate;

    // 身份证号
    private String idNum;

    // 手机号
    private String phoneNum;

    // 目的地
    private Region place;

    // 邮箱
    private String email;

    /*---------新增---------------------------------------------------------------------------*/

    // 获取InsuranceOrder类的json数据
    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("productName", productName);
        map.put("clientName", clientName);
        map.put("orderAmount", orderAmount);

        map.put("idNum", idNum);
        map.put("phoneNum", phoneNum);
        map.put("email", email);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        map.put("orderTime", sdf.format(orderTime));
        map.put("startTime", sdf.format(startDate));
        map.put("endTime", sdf.format(endDate));

        if (product != null) {
            map.put("insuranceProductId", product.getId());
            map.put("insuranceProduct_state", product.getState());
        }

        if (insurance != null) {
            map.put("insuranceId", insurance.getId());
            map.put("insuranceName", insurance.getName());
        }

        if (place != null) {
            map.put("placeId", place.getId());
            map.put("placeName", place.getName());
        }

        return JSONUtil.toJSONString(map);
    }

}